package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

import Bizlogic.CAManager;
import Model.EmailBean;
import Model.Product;
import Util.EmailUtil;

public class partstobeOrdered extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		CAManager cManager=new CAManager();
		List<Product> list=cManager.findProductslessStock();
		request.setAttribute("list", list);
		StringBuffer sb= new StringBuffer();
		System.out.print(list.size());
		for (Product product : list) {
			sb.append("part number"+product.getProductnum()+"need to be reordered");
		}
		
		EmailBean eBean=new EmailBean();
		eBean.setHostName("smtp.163.com");
		eBean.setPort(25);
		eBean.setSenderId("javacasender@163.com");
		eBean.setSenderPassword("123456");
		eBean.setDestinationAddress("javacaget@163.com");
		eBean.setSubject("Test");
		eBean.setContent(sb.toString());
		EmailUtil.sendTextMail(eBean);
		request.getRequestDispatcher("MaintainInvertoryStock.jsp").forward(request, response);		
	}
	
	

	
	
	

}
